package com.rd.student.jike.class2.lihongming.week731_806.Day0804;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @Auther:Heinrich
 * @Date:2023/8/4-08-04-11:22
 * @Description:com.rd.student.jike.class2.lihongming.Day0804
 * @version:1.0
 */
public class Cross3 implements Runnable {

    AtomicInteger temp = new AtomicInteger(1);

    @Override
    public void run() {
        long start = System.currentTimeMillis();
        try {
            Thread.sleep((long) (Math.random() * 5000));
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        long end = System.currentTimeMillis();
        System.out.println(Thread.currentThread().getName() + "通过山洞花费了" + (end - start));
        temp.getAndIncrement();
        if (Integer.parseInt(String.valueOf(temp)) == 11) {
            System.out.println("已全部通过山洞");
        }
    }
}


class Test3 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {

        Cross3 cross = new Cross3();
        new Thread(cross, "贾复").start();
        new Thread(cross, "贾似道").start();
        new Thread(cross, "史弥远").start();
        new Thread(cross, "张俊").start();
        new Thread(cross, "刘光世").start();
        new Thread(cross, "韩世忠").start();
        new Thread(cross, "王阳明").start();
        new Thread(cross, "马周").start();
        new Thread(cross, "姚崇").start();
        new Thread(cross, "宋璟").start();
    }
}